package com.zzty.dendi.controller;

import com.zzty.dendi.entity.User;
import com.zzty.dendi.entity.UserPage;
import com.zzty.dendi.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/user")
public class UserController {
    @Autowired
    UserService userService;

    @RequestMapping("test")
    @ResponseBody
    public User test(){
        User user=new User();
        user.setName("aaa");
        //user.setAge(11);
        return user;
    }

    @RequestMapping("test1")
    @ResponseBody
    public String test1(){
        User user=new User();
        user.setName("aaa");
        //user.setAge(11);
        return "success";
    }


    @RequestMapping(value="add",method = RequestMethod.POST)
    @ResponseBody
    public User add(@RequestBody User user){
        System.out.println(user);
        return user;
    }

    @ResponseBody
    @RequestMapping(value="addUser1",method = RequestMethod.POST)
    public User addUser(@RequestBody User user){

        System.out.println(user);
        return user;
    }
    @ResponseBody
    @RequestMapping(value="getUser")
    public User getUser(@RequestParam(value="name") String name){
        User user=new User();
        user.setName("aaa");
        //user.setAge(11);
        return user;
    }
    @ResponseBody
    @RequestMapping(value="getUsers")
    public List<User> getUsers(@RequestParam(value="name") String name){
        List<User> users =new ArrayList<User>();

        User user=new User();
        user.setName("aaa");
        User user1=new User();
        user1.setName("bbb");
        //user.setAge(11);
        users.add(user);
        users.add(user1);
        return users;
    }

    @ResponseBody
    @RequestMapping(value="getUserByPageNo/{pageNo}")
    public UserPage getUserByPageNo(@PathVariable("pageNo") Integer pageNo){
        return userService.getUserByPageNo(pageNo);
    }

    @ResponseBody
    @RequestMapping(value="updateUser")
    public Map updateUser(User user){
        System.out.println(user);
        Map<String,String> map=new HashMap<String,String>();
        map.put("result","success");
        return map;
    }




}
